<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/js/layui-v2.4.5/layui/css/layui.css}" media="all" />
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all" />
</head>
<body  style="-webkit-backface-visibility: hidden;">

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加设备</legend>
</fieldset>

<form class="layui-form"  lay-filter="example">
    <div class="layui-form-item">
        <label class="layui-form-label">所属公司：</label>
        <div class="layui-input-block">
            <select name="belongCompany" lay-filter="belongCompany" >
                <option th:each="company:${companys}" th:value="${company.value}"  th:text="${company.desc}">合富置业</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">所属部门：</label>
        <div class="layui-input-block">
            <input type="text" name="belongUnit"  autocomplete="off" placeholder="请输入部门名"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">设备编号：</label>
        <div class="layui-input-block">
            <input type="text" name="num"  autocomplete="off" lay-verify="required"  placeholder="请输入设备唯一编号"  class="layui-input" maxlength="40">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">设备商：</label>
        <div class="layui-input-block">
            <select name="equipment" lay-filter="equipment" >
                <option th:each="equipment:${equipments}" th:value="${equipment.value}"  th:text="${equipment.desc}"></option>
            </select>
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">机房：</label>
        <div class="layui-input-block">
            <select name="computerRoom" lay-filter="computerRoom">
                <option th:each="computerRoom:${computerRooms}" th:value="${computerRoom.value}"  th:text="${computerRoom.desc}"></option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">机架：</label>
        <div class="layui-input-block">
            <input type="text" name="rack"  autocomplete="off" lay-verify="required"  placeholder="请输入机架编号"  class="layui-input" maxlength="40">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">sip账号：</label>
        <div class="layui-input-block">
            <input type="text" name="sipUser"  autocomplete="off" lay-verify="required"  placeholder="请输入sip账号"  class="layui-input" maxlength="50">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">IP：</label>
        <div class="layui-input-block">
            <input type="text" name="ip" lay-verify="required" autocomplete="off"  placeholder="请输入ip"  class="layui-input" value=""  maxlength="30">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">端口：</label>
        <div class="layui-input-block">
            <input type="text" name="port" lay-verify="required" autocomplete="off"  placeholder="请输入端口"  class="layui-input" value="" onkeyup="this.value=this.value.replace(/\D/g,'')"
                   onafterpaste="this.value=this.value.replace(/\D/g,'')"  maxlength="10"/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">网关类型：</label>
        <div class="layui-input-block">
            <select name="type" lay-filter="type">
                <option th:each="gatewayType:${gatewayTypes}" th:value="${gatewayType.value}"  th:text="${gatewayType.desc}"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">卡槽数量：</label>
        <div class="layui-input-block">
            <input type="text" name="slotNum" lay-verify="required" autocomplete="off"  placeholder="请输入卡槽数量"  class="layui-input" value="" onkeyup="this.value=this.value.replace(/\D/g,'')"
                   onafterpaste="this.value=this.value.replace(/\D/g,'')"  maxlength="10"/>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注：</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入备注内容" name="remark" class="layui-textarea" maxlength="200"></textarea>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block" style="text-align: center">
            <button type="button" class="layui-btn layui-btn-normal" id ="back">返回</button>
            <button   class="layui-btn" lay-submit lay-filter="save">保存</button>
        </div>
    </div>
</form>
<script th:src="@{/js/jquery-2.1.1.min.js}"></script>
<script th:src="@{/js/layui-v2.4.5/layui/layui.js}"></script>
<script th:src="@{/js/utils.js}"></script>
<script th:inline="javascript">

</script>
<style>
    .layui-form-label{    width: 100px!important;}
    .layui-input-block{    margin-left: 135px!important;}
</style>
<script>
    layui.use(['form','laydate'], function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : parent.layer;
            selectPlus = layui.selectPlus,
            $ = layui.jquery, laydate = layui.laydate;


        $("#back").click(function () {
            var index=layer.getFrameIndex(window.name); //获取当前窗口的name
            layer.close(index);

        })


        /**
         *
         *监听提交
         * */
        form.on('submit(save)', function(data){
            var data = data.field;
            var load = layer.load();
            $.ajax({
                type: "POST",
                url:  path+'/gatewayinfo/saveGateway',
                dataType:"json",
                data:data,
                success: function (data) {
                    layer.close(load);
                    if(data.code=="1"){
                        layer.msg(data.msg,{icon: 6})
                        window.parent.hasSave=true;
                        var index=layer.getFrameIndex(window.name); //获取当前窗口的name
                        layer.close(index);
                    }else{
                        layer.msg(data.msg,{icon: 5})
                    }
                },
                error: function (msg) {
                    layer.close(load);
                }
            });
            return false;
        });
    });

</script>

</body>
</html>